<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .wrap {
            width: 340px;
            border: 1px solid black;
            border: 15px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .welcome {
            background-color: chartreuse;
            border-radius: 15px;
            height: 30px;
            width: 150px;
            text-align: center;
            line-height: 30px;
            font-size: 20px;
            color: white;
            font-weight: 700;
            margin-bottom: 20px;
        }

        .name,
        .password1,
        .password2 {
            width: 340px;
            height: 50px;
            line-height: 50px;
            padding-left: 20px;
            border-radius: 25px;
            margin-bottom: 10px;
        }

        .name {
            margin-bottom: 25px;
        }

        .p1,
        .p2,
        .p3 {
            color: red;
            visibility: hidden;
        }

        .sure {
            background-color: rgb(233, 233, 46);
            border-radius: 15px;
            height: 30px;
            width: 200px;
            text-align: center;
            line-height: 30px;
            font-size: 20px;
            color: white;
            font-weight: 700;
            margin-bottom: 20px
        }
        input{outline: none;}
    </style>
</head>

<body>
    <div class="wrap">
        <div class="welcome">欢迎登陆</div>
        <input type="text" class="name" placeholder="请输入昵称">
        <p class="p1">字母开头，允许5-16字节，允许字母数字下划线</p>
        <input type="password" class="password1" placeholder="请输入密码">
        <p class="p2">以字母开头，长度在6~18之间，只能包含字母、数字和下划线</p>
        <input type="password" class="password2" placeholder="请确认密码">
        <p class="p3">请确保与第一次密码一致</p>
        <div class="sure">确认注册</div>
    </div>
</body>

<script src="../js/jquery-3.6.0.js"></script>
<script>
    // 失焦判断
    // 昵称判断
    function name1(){
        let reg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/
        if (reg.test($('.name').val())) {
            $('.p1').css('visibility', 'hidden')
        } else {
            $('.p1').css('visibility', 'visible')
        }
    }
    $('.name').on('blur', function () {
       name1()
    })
    // 密码判断
    function password1(){
        let reg = /^[a-zA-Z]\w{5,17}$/
        if (reg.test($('.password1').val())) {
            $('.p2').css('visibility', 'hidden')
        } else {
            $('.p2').css('visibility', 'visible')
        }
    }
    $('.password1').on('blur', function () {
       password1()
    })
    // 密码二次判断
    function password2(){
        if ($('.password1').val() == $('.password2').val()) {
            $('.p3').css('visibility', 'hidden')
        } else {
            $('.p3').css('visibility', 'visible')
        }
    }
    $('.password2').on('blur', function () {
       password2()
    })
    $('.sure').on('click',function(){
        let rr=$('p').filter(function(){
            return $(this).css('visibility')=='hidden';
        })
       if(rr.length==3){
        let name2=$(".name").val()
        let password=$('.password1').val()
        let accountInformation={name2,password}
        localStorage.setItem('INFORMATION',JSON.stringify(accountInformation))
        location.href='logIn.html'
       }else{
           alert('请按要求输入')
       }
    })
</script>

</html>